<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="产品项目" prop="ggcmProductId">
									<el-input v-model="form.ggcmProductId" placeholder="请输入产品项目" clearable></el-input>
								</el-form-item>
								<el-form-item label="种类" prop="ggcmCategoryId">
									<el-input v-model="form.ggcmCategoryId" placeholder="请输入种类" clearable></el-input>
								</el-form-item>
								<el-form-item label="企业" prop="companyId">
									<el-input v-model="form.companyId" placeholder="请输入企业" clearable></el-input>
								</el-form-item>
								<el-form-item label="名称" prop="pname">
									<el-input v-model="form.pname" placeholder="请输入名称" clearable></el-input>
								</el-form-item>
								<el-form-item label="编码" prop="pno">
									<el-input v-model="form.pno" placeholder="请输入编码" clearable></el-input>
								</el-form-item>
								<el-form-item label="拼音" prop="pinyin">
									<el-input v-model="form.pinyin" placeholder="请输入拼音" clearable></el-input>
								</el-form-item>
								<el-form-item label="排序 降序" prop="seq">
									<el-input v-model="form.seq" placeholder="请输入排序 降序" clearable></el-input>
								</el-form-item>
								<el-form-item label="1激活 0失效" prop="state">
									<el-input v-model="form.state" placeholder="请输入1激活 0失效" clearable></el-input>
								</el-form-item>
								<el-form-item label="规格关键字#K号隔开" prop="jfValue">
									<el-input v-model="form.jfValue" placeholder="请输入规格关键字#K号隔开" clearable></el-input>
								</el-form-item>
								<el-form-item label="对外报价描述" prop="jfDesc">
									<el-input v-model="form.jfDesc" placeholder="请输入对外报价描述" clearable></el-input>
								</el-form-item>
								<el-form-item label="设计成本" prop="priceSj">
									<el-input v-model="form.priceSj" placeholder="请输入设计成本" clearable></el-input>
								</el-form-item>
								<el-form-item label="安装成本" prop="priceCbaz">
									<el-input v-model="form.priceCbaz" placeholder="请输入安装成本" clearable></el-input>
								</el-form-item>
								<el-form-item label="通用成本" prop="priceCb">
									<el-input v-model="form.priceCb" placeholder="请输入通用成本" clearable></el-input>
								</el-form-item>
								<el-form-item label="包安装销售价格" prop="priceSjaz">
									<el-input v-model="form.priceSjaz" placeholder="请输入包安装销售价格" clearable></el-input>
								</el-form-item>
								<el-form-item label="成本单位" prop="priceCbdw">
									<el-input v-model="form.priceCbdw" placeholder="请输入成本单位" clearable></el-input>
								</el-form-item>
								<el-form-item label="价格说明" prop="priceDesc">
									<el-input v-model="form.priceDesc" placeholder="请输入价格说明" clearable></el-input>
								</el-form-item>
								<el-form-item label="最后更新时间" prop="utime">
									<el-input v-model="form.utime" placeholder="请输入最后更新时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="备注" prop="msg">
									<el-input v-model="form.msg" placeholder="请输入备注" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: ''
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					ggcmProductId: "",
					ggcmCategoryId: "",
					companyId: "",
					pname: "",
					pno: "",
					pinyin: "",
					seq: "",
					state: "",
					jfValue: "",
					jfDesc: "",
					priceSj: "",
					priceCbaz: "",
					priceCb: "",
					priceSjaz: "",
					priceCbdw: "",
					priceDesc: "",
					utime: "",
					msg: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await this.$API.ggcm.ggcmProduct.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.ggcmProductId = data.ggcmProductId;
				this.form.ggcmCategoryId = data.ggcmCategoryId;
				this.form.companyId = data.companyId;
				this.form.pname = data.pname;
				this.form.pno = data.pno;
				this.form.pinyin = data.pinyin;
				this.form.seq = data.seq;
				this.form.state = data.state;
				this.form.jfValue = data.jfValue;
				this.form.jfDesc = data.jfDesc;
				this.form.priceSj = data.priceSj;
				this.form.priceCbaz = data.priceCbaz;
				this.form.priceCb = data.priceCb;
				this.form.priceSjaz = data.priceSjaz;
				this.form.priceCbdw = data.priceCbdw;
				this.form.priceDesc = data.priceDesc;
				this.form.utime = data.utime;
				this.form.msg = data.msg;
			}
		}
	}
</script>
<style>
</style>
